package object;

public class PolyClass3 {
	public static void main(String[] args) {
		People p1 = new People(20, "王");
		Animal a1 = new Cat(2, "白");
		p1.keepPet(a1, "111");
	}
}

class Animal {
	private int age;
	private String color;
	static String name ="999";


	public Animal() {
	}

	public Animal(int age, String color) {
		this.age = age;
		this.color = color;
	}

	/**
	 * 获取
	 *
	 * @return age
	 */
	public int getAge() {
		return age;
	}

	/**
	 * 设置
	 *
	 * @param age
	 */
	public void setAge(int age) {
		this.age = age;
	}

	/**
	 * 获取
	 *
	 * @return color
	 */
	public String getColor() {
		return color;
	}

	/**
	 * 设置
	 *
	 * @param color
	 */
	public void setColor(String color) {
		this.color = color;
	}

	public void eat(String something) {
		System.out.println("Animal is eating" + something);
	}
}

class Cat extends Animal {
	public Cat() {

	}

	public Cat(int age, String color) {
		super(age, color);
		System.out.println(name);
	}

	@Override
	public void eat(String something) {
		System.out.println("cat is eating:" + something);
	}

	public void fish() {
		System.out.println("fish");
	}
}

//class Dog extends Animal {
//	public Dog(int age, String color) {
//		super(age, color);
//	}
//}

class People {
	private int age;
	private String name;


	public People() {
	}

	public People(int age, String name) {
		this.age = age;
		this.name = name;
	}

	public void keepPet(Animal animal, String something) {
		// System.out.println(animal.getColor() + " , " + animal.getAge());
		// animal.eat(something);
		if(animal instanceof Cat c) {
			System.out.println(c.getColor() + " , " + c.getAge());
			c.eat(something);
			c.fish();
		}
	}
}

